package com.dingup.mock.handler;

import com.dingup.mock.bean.listening.ListeningArticlePicture;
import com.dingup.mock.util.XmlUtil;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by yanggavin on 16/4/16.
 */
public class ListeningArticlePicInfoHandler extends BaseTypeHandler<List<ListeningArticlePicture>> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, List<ListeningArticlePicture> parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, XmlUtil.genListeningArticlePicInfoXmlContent(parameter));
    }

    @Override
    public List<ListeningArticlePicture> getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return XmlUtil.parseListeningArticlePicInfo(rs.getString(columnName));
    }

    @Override
    public List<ListeningArticlePicture> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return XmlUtil.parseListeningArticlePicInfo(rs.getString(columnIndex));
    }

    @Override
    public List<ListeningArticlePicture> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return XmlUtil.parseListeningArticlePicInfo(cs.getString(columnIndex));
    }
}
